﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Runtime.Serialization.Json;

namespace EGov
{
    public partial class chitiettintuc : PhoneApplicationPage
    {
        List<Place> ListTinTuc = new List<Place>();
        public chitiettintuc()
        {
            InitializeComponent();
            string tinmoi = "http://egov047.juddy.vn/api/place";
            WebClient client = new WebClient();
           
            client.OpenReadCompleted += new OpenReadCompletedEventHandler(client_OpenReadCompleted);
            client.OpenReadAsync(new Uri(tinmoi), UriKind.Absolute);       
        }
        List<ListBox> listb = new List<ListBox>();
        void client_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
        {
            MyPanoram.Items.Clear();
            try
            {
                var ser = new DataContractJsonSerializer(typeof(List<Place>), null);
                ListTinTuc = (List<Place>)ser.ReadObject(e.Result);
                for (int i = 0; i < ListTinTuc.Count;i++ )
                {
                   
                    if( ListTinTuc[i].Image==""||ListTinTuc[i].Image==null)
                     ListTinTuc[i].Image = "http://egov047.juddy.vn/_serviceData/Images/77.jpg";                   
                    //image.Source = new System.Windows.Media.Imaging.BitmapImage(new Uri(uriplaceimage));
                    List<Place> tamp = new List<Place>();
                    tamp.Add(ListTinTuc[i]);
                    //ListBox lbhinh = new ListBox();
                    //lbhinh.ItemTemplate = this.lstListTin;
                    ListBox lb = new ListBox();
                    lb.ItemTemplate = lstListTin.ItemTemplate;
                    lb.ItemsSource =tamp;
                    PanoramaItem pi = new PanoramaItem();
                    //pi.Name = "_PanoramaItem" + i;
                    int j = i + 1;
                   pi.Header = "Tin " + j;
                    pi.Content = lb;
                    MyPanoram.Items.Add(pi);
                }
               

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

        private void MyPanoram_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {

        } 
      
    }
}